package demo;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86185
 * Date: 2023-05-29
 * Time: 8:51
 */
class Point {
    private int xPos, yPos;
    public Point(int x, int y) {
        xPos = x;
        yPos = y;
    }

    @Override
    public boolean equals(Object obj) {
        Point point = (Point) obj;
        if (this.xPos == point.xPos && this.yPos == point.yPos) {
            return true;
        }
        return false;
    }
}
interface Employee2 {
    int getSalary();
}
class Manager implements Employee2 {

    int money;

    public Manager(int money) {
        this.money = money;
    }

    @Override
    public int getSalary() {
        return money;
    }
}
class Salesman implements Employee2 {
    int money;
    int commission;

    public Salesman(int money, int commission) {
        this.money = money;
        this.commission = commission;
    }

    @Override
    public int getSalary() {
        return money + commission;
    }
}
class Worker implements Employee2{
    int days;
    int money;

    public Worker(int days, int money) {
        this.days = days;
        this.money = money;
    }

    @Override
    public int getSalary() {
        return days * money;
    }
}
interface Person {
    void eat();
    void sleep();
}
class Student implements Person {

    @Override
    public void eat() {
        System.out.println("学生去食堂吃饭。");
    }

    @Override
    public void sleep() {
        System.out.println("学生在宿舍睡觉。");
    }
}
class Teacher implements Person {


    @Override
    public void eat() {
        System.out.println("老师去教师食堂吃饭。");
    }

    @Override
    public void sleep() {
        System.out.println("老师在学校公寓睡觉。");
    }
}
class RDMP {
    public void fuc1(char[] music) {
        char c = music[0];
        for (int i = 0; i < music.length - 1; i++) {
            music[i] = music[i + 1];
        }
        music[music.length - 1] = c;
    }
    public void fuc2(char[] music) {
        char c = music[music.length - 1];
        for (int i = music.length - 1; i > 0; i--) {
            music[i] = music[i - 1];
        }
        music[0] = c;
    }
    public void fuc3(char[] music) {
        char c = music[0];
        music[0] = music[1];
        music[1] = c;
    }
}
class Matrix {
    int[][] arr;
    int row;
    int col;

    public Matrix(int row, int col) {
        this.arr = new int[row][col];
        this.row = row;
        this.col = col;
    }

    public void set(int row , int col , int value) {
        arr[row][col] = value;
    }
    public int get(int row,int col) {
        return arr[row][col];
    }
    public int width() {
        return col;
    }
    public int height() {
        return row;
    }
    public Matrix add(Matrix b) {
        Matrix matrix = b;
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++) {
                matrix.arr[i][j] = arr[i][j] + b.arr[i][j];
            }
        }
        return matrix;
    }
    public Matrix multiply(Matrix b) {
        Matrix matrix = new Matrix(row, b.col);
        for (int i = 0; i < row; i++) {
            for (int j = 0; j < b.col; j++) {
                for (int k = 0; k < col; k++) {
                    matrix.arr[i][j] += arr[i][k] * b.arr[k][j];
                }
            }
        }
        return matrix;
    }
    public Matrix transpose() {
        Matrix matrix = new Matrix(row, col);
        for (int i = 0; i < row; i++) {
            for (int j = 0; j < col; j++) {
                matrix.arr[j][i] = arr[i][j];
            }
        }
        return matrix;
    }


    public String toString() {
        for (int i = 0; i < row; i++) {
            for (int j = 0; j < col; j++) {
                if(j == 0) {
                    System.out.print(arr[i][j]);
                } else {
                    System.out.print(" " + arr[i][j]);
                }
            }
            System.out.println();
        }
        return null;
    }
}
abstract class BallMatch {
    String point;

    public BallMatch(String point) {
        this.point = point;
    }

    public void checkin() {
        System.out.println("now checking in");
    }
    public void start() {
        System.out.println("now starting");
    }
    public abstract void play();
    public void end() {
        System.out.println("now ending");
    }
    public void annouceResult() {
        System.out.println("now annoucing result: " + point);
    }
}
class FootballMatch extends BallMatch {

    public FootballMatch(String point) {
        super(point);
    }

    @Override
    public void play() {
        System.out.println("now playing football");
    }
}
class BasketBallMatch extends BallMatch {

    public BasketBallMatch(String point) {
        super(point);
    }

    @Override
    public void play() {
        System.out.println("now playing basketball");
    }
}
class Employee implements Comparable<Employee>{
    private int ID;
    private String name;
    private String sex;
    private int group;
    private int individual;

    public Employee() {
    }

    public Employee(int ID, int group, int individual, String name, String sex) {
        this.ID = ID;
        this.name = name;
        this.sex = sex;
        this.group = group;
        this.individual = individual;
    }

    public int getID() {
        return ID;
    }

    public void setID(int ID) {
        this.ID = ID;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public int getGroup() {
        return group;
    }

    public void setGroup(int group) {
        this.group = group;
    }

    public int getIndividual() {
        return individual;
    }

    public void setIndividual(int individual) {
        this.individual = individual;
    }

    @Override
    public int compareTo(Employee o) {
        return this.group + this.individual - o.group - o.individual;
    }

    @Override
    public String toString() {
        return  ID +
                "," + group +
                "," + individual +
                "," + name +
                "," + sex;
    }
}
class iCompareByGroup implements Comparator<Employee> {
    @Override
    public int compare(Employee o1, Employee o2) {
        return o1.getGroup() - o2.getGroup();
    }
}
interface IntegerStack {
    public Integer push(Integer item);
//如果item为null，则不入栈直接返回null。如果栈满，也返回null。如果插入成功，返回item。

    public Integer pop();   //出栈，如果为空，则返回null。出栈时只移动栈顶指针，相应位置不置为null
    public Integer peek();  //获得栈顶元素，如果为空，则返回null.
    public boolean empty(); //如果为空返回true
    public int size();      //返回栈中元素个数
}
class ArrayIntegerStack implements IntegerStack {

    public Integer[] num ;
    public int usedSize = 0;

    public ArrayIntegerStack(){}
    public ArrayIntegerStack(int n) {
        this.num = new Integer[n];
    }

    @Override
    public Integer push(Integer item) {
        if(usedSize == num.length) {
            return null;
        }
        num[usedSize++] = item;
        return item;
    }

    @Override
    public Integer pop() {
        if(usedSize == 0) {
            return null;
        }
        return num[--usedSize];
    }

    @Override
    public Integer peek() {
        if(empty()) {
            return null;
        }
        return num[usedSize - 1];
    }

    @Override
    public boolean empty() {
        return usedSize == 0;
    }

    @Override
    public int size() {
        return usedSize;
    }
}
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        ArrayIntegerStack stack = new ArrayIntegerStack(n);
        int m = scanner.nextInt();
        for (int i = 0; i < m; i++) {
            System.out.println(stack.push(scanner.nextInt()));
        }
        System.out.println(stack.peek() + "," + stack.empty() + "," + stack.size());
        System.out.println(Arrays.toString(stack.num));
        int x = scanner.nextInt();
        for (int i = 0; i < x; i++) {
            System.out.println(stack.pop());
        }
        System.out.println(stack.peek() + "," + stack.empty() + "," + stack.size());
        System.out.println(Arrays.toString(stack.num));
    }
    public static void main6(String[] args) {
        Employee[] employees = new Employee[5];
        employees[0] = new Employee(1,500,400,"职工1","female");
        employees[1] = new Employee(2,400,600,"职工2","female");
        employees[2] = new Employee(3,600,300,"职工3","male");
        employees[3] = new Employee(4,800,200,"职工4","female");
        employees[4] = new Employee(5,500,700,"职工5","male");

        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 4 - i; j++) {
                if(employees[j].compareTo(employees[j + 1]) > 0) {
                    Employee employee = employees[j];
                    employees[j] = employees[j + 1];
                    employees[ j + 1] = employee;
                }
            }
        }
        System.out.println("编号,团险,个险,姓名,性别");
        for (int i = 0; i < 5; i++) {
            System.out.println(employees[i]);
        }
        iCompareByGroup cmp = new iCompareByGroup();
        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 4 - i; j++) {
                if(cmp.compare(employees[j], employees[j + 1]) > 0) {
                    Employee employee = employees[j];
                    employees[j] = employees[j + 1];
                    employees[ j + 1] = employee;
                }
            }
        }
        System.out.println("编号,团险,个险,姓名,性别");
        for (int i = 0; i < 5; i++) {
            System.out.println(employees[i]);
        }
    }
    public static void main2(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        BallMatch ballMatch = null;
        if(n == 1) {
            ballMatch = new FootballMatch(scanner.next());
        } else {
            ballMatch = new BasketBallMatch(scanner.next());
        }
        ballMatch.checkin();
        ballMatch.start();
        ballMatch.play();
        ballMatch.end();
        ballMatch.annouceResult();
    }
    public static void main1(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int row = scanner.nextInt();
        int col = scanner.nextInt();
        System.out.println("row:" + row+ " column:" + col);
        Matrix matrix = new Matrix(row, col);
        for (int i = 0; i < row; i++) {
            for (int j = 0; j < col; j++) {
                matrix.arr[i][j] = scanner.nextInt();
            }
        }
        matrix.set(scanner.nextInt()- 1, scanner.nextInt()- 1, scanner.nextInt());
        System.out.println("after set value:");
        matrix.toString();
        int x1 = scanner.nextInt()- 1;
        int y1 = scanner.nextInt()- 1;
        int ans = matrix.get(x1, y1);
        System.out.println("value on (" + (x1 + 1) +"," + (y1 + 1) + "):" + ans);
        int row2 = scanner.nextInt();
        int col2 = scanner.nextInt();
        Matrix matrix1 = new Matrix(row2, col2);
        for (int i = 0; i < row2; i++) {
            for (int j = 0; j < col2; j++) {
                matrix1.arr[i][j] = scanner.nextInt();
            }
        }
        System.out.println("after add:");
        Matrix matrix2 = matrix.add(matrix1);
        matrix2.toString();
        int row3 = scanner.nextInt();
        int col3 = scanner.nextInt();
        Matrix matrix3 = new Matrix(row3, col3);
        for (int i = 0; i < row3; i++) {
            for (int j = 0; j < col3; j++) {
                matrix3.arr[i][j] = scanner.nextInt();
            }
        }
        Matrix matrix4 = matrix.multiply(matrix3);
        System.out.println("after multiply:");
        matrix4.toString();
        matrix = matrix.transpose();
        System.out.println("after transpose:");
        matrix.toString();
    }
    public static int[][] clockwise90(int[][] num, int n) {
        int[][] tmp = new int[n][n];
        for (int j = 0; j < n; j++) {
            for (int i = n - 1; i >= 0; i--) {
                tmp[j][n - 1 - i] = num[i][j];
            }
        }
        return tmp;
    }

    public static int[][] anticlockwise90(int[][] num, int n) {
        int[][] tmp = new int[n][n];
        for (int j = n - 1; j >= 0; j--) {
            for (int i = 0; i < n; i++) {
                tmp[n - j - 1][i] = num[i][j];
            }
        }
        return tmp;
    }
    public static int[][] clockwise180(int[][] num, int n) {
        int[][] tmp = new int[n][n];
        for (int j = n - 1; j >= 0; j--) {
            for (int i = n - 1; i >= 0; i--) {
                tmp[n - i - 1][n - j - 1] = num[i][j];
            }
        }
        return tmp;
    }
    public static void main5(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int option = scanner.nextInt();
        int[][] num = new int[n][n];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                num[i][j] = scanner.nextInt();
            }
        }
        if(option == 90) {
            num = clockwise90(num, n);
        } else if (option == -90) {
            num = anticlockwise90(num, n);
        } else {
            num = clockwise180(num, n);
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if(j == 0) {
                    System.out.print(num[i][j]);
                } else {
                    System.out.print(" " + num[i][j]);
                }
            }
            System.out.println();
        }
    }
    public static void san(int[][] num) {
        int flag = 0;
        for (int i = 1; i < num.length - 1; i++) {
            for (int j = 1; j < num.length - 1; j++) {
                if(num[i][j] > num[i][j + 1] && num[i][j] > num[i][j - 1] &&
                num[i][j] > num[i - 1][j] && num[i][j] > num[i + 1][j] &&
                num[i][j] > num[i - 1][j - 1] && num[i][j] > num[i - 1][j + 1] &&
                num[i][j] > num[i + 1][j - 1] && num[i][j] > num[i + 1][j + 1]) {
                    System.out.print(num[i][j] + " ");
                    flag = 1;
                }
            }
        }

        if(flag == 0) {
            System.out.print("none");
        }
        System.out.println();
    }
    public static void main4(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            int n = scanner.nextInt();
            int[][] num = new int[n + 2][n + 2];
            for (int i = 1; i < n + 1; i++) {
                num[i][0] = -1;
                num[i][n + 1] = -1;
            }
            for (int i = 0; i < n + 2; i++) {
                num[0][i] = -1;
                num[n + 1][i] = -1;
            }
            for (int i = 1; i < n + 1; i++) {
                for (int j = 1; j < n + 1; j++) {
                    num[i][j] = scanner.nextInt();
                }
            }
            san(num);
        }


    }
    public static void main3(String[] args) {
        char[] musicAll = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
        Scanner scanner = new Scanner(System.in);
        int m = scanner.nextInt();
        char[] music = Arrays.copyOf(musicAll, m);
        int n = scanner.nextInt();
        RDMP rdmp = new RDMP();
        for (int i = 0; i < n; i++) {
            int tmp = scanner.nextInt();
            if(tmp == 1) {
                rdmp.fuc1(music);
            } else if (tmp == 2) {
                rdmp.fuc2(music);
            } else {
                rdmp.fuc3(music);
            }
        }
        for (int i = 0; i < m; i++) {
            if(i == 0) {
                System.out.print(music[i]);
            } else {
                System.out.print("," + music[i]);
            }
        }
    }
}
